<?php

namespace app\agent\service;

use app\agent\logic\StatisticsBankLogic;
use app\agent\logic\StatisticsTurnoverLogic;
use app\agent\logic\StatisticsWljfLogic;
use app\agent\logic\UserLogic;
use app\agent\logic\WkSellerLogic;
use app\agent\servlet\WkSellerServlet;

class WkSellerService extends BaseService
{
    private $wkSeller = null;

    private $servlet = null;

    private $statisticsBank = null;

    private $statisticsTurnover = null;

    private $statisticsWljf = null;

    private $user = null;

    private $wkOrderService = null;

    public function __construct()
    {
        parent::__construct();

        $this->wkSeller = new WkSellerLogic();

        $this->servlet = new WkSellerServlet();

        $this->statisticsBank = new StatisticsBankLogic();

        $this->statisticsTurnover = new StatisticsTurnoverLogic();

        $this->statisticsWljf = new StatisticsWljfLogic();

        $this->user = new UserLogic();

        $this->wkOrderService = new WkOrderService();
    }

    public function getViewPage($request = [])
    {
        $request = $this->servlet->collating($request);

        $where = $this->servlet->getWhere($request);

        $data = $this->wkSeller->getPage($where, $request);

        $data = [
            'data'      => $data,
            'status'    => $this->wkSeller->_map['status'],
        ];

        return $data;
    }

    public function getExcel($request = [])
    {
        $request = $this->servlet->collating($request);

        $where = $this->servlet->getWhere($request);

        $data = $this->wkSeller->getExcel($where, $request);

        $data = [
            'data'      => $data,
            'status'    => $this->wkSeller->_map['status'],
        ];

        return $data;
    }

    /**
     * @action 商家列表详情
     */
    public function getViewDetail($data = [])
    {
        $where = $this->servlet->getWhere($data);

        $data = $this->wkSeller->getDetail($where);

        //获取商家粉丝
        $where = [
            ['bindseller', '=', $data['uid']],
        ];
        $data['fensi'] = $this->user->getFensiCount($where);

        if( $data === false )
        {
            $this->error = $this->wkSeller->getError();

            return false;
        }

        return $data;
    }
}